package com.cloudwise.controller;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloudwise.entity.*;
import com.cloudwise.service.LogService;
import com.cloudwise.service.TesterService;
import com.cloudwise.util.Constants;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2021/11/29 15:35
 * @description：日志业务控制器
 * @modified By：
 * @version: 1.0
 */
@RestController
@RequestMapping("log")
public class LogController extends BaseController {
    @Resource
    private LogService logService;
    /**
     * @create by: Teacher陈（86521760@qq.com）
     * @description: 日志查询
     * @create time: 2021/12/8 15:59
     * @param page 当前第几页
     * @param limit 一页显示多少航
     * @param log 日志对象
     * @return com.cloudwise.entity.ReturnBean
     */
    @RequestMapping("selectAllPage")
    public ReturnBean selectAllPage(Long page, Long limit, Log log) {
        //重新构建分页对象
        if(page==null){
            page= Constants.page;
            limit=Constants.limit;
        }
        Page<Log> pageObj = new Page<>(page, limit);
        //日志条件查询对象
        QueryWrapper<Log> logQueryWrapper = new QueryWrapper<>();
        if(ObjectUtil.isNotEmpty(log.getLoginName())){
            logQueryWrapper.like("login_name",log.getLoginName());
        }
        if(ObjectUtil.isNotEmpty(log.getMethodName())){
            logQueryWrapper.like("method_name",log.getMethodName());
        }
        //排序
        logQueryWrapper.orderByDesc("id");
        Page<Log> logPage = this.logService.page(pageObj,logQueryWrapper );
        return super.success(logPage.getRecords(),logPage.getTotal());
    }


}
